package com.maya.controller;

import java.util.ArrayList;
import java.util.List;

import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.maya.model.User;
import com.maya.service.UserService;



@Controller

public class ViewUserFollowingsController  {
	
	@Autowired
	private UserService userService;
	
	@RequestMapping("/viewuserfollowings")
    public String viewuserfollowings(String viewedid,Model model) {
        
        User viewedUser = userService.get(new ObjectId(viewedid));
        List<ObjectId> followingIds = viewedUser.getFollowingIds();
        List<User> followings = new ArrayList<User>();

        for(ObjectId id: followingIds) {
            User u = userService.get(id);
            followings.add(u);
        }
        System.out.println(followings.size() + "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&");
        model.addAttribute("followings", followings);
        model.addAttribute("vieweduser", viewedUser);
        
        return "user-followings";
               
        
    }
}
